from appium import webdriver
from Utils.XiaoMaUtils import XiaoMaUtils


def init_driver():
    """
    初始化driver

    :param use_launcher: 是否启动桌面, 默认为False, 不启动桌面, 直接启动对应应用
    :param clear_package_name: 要清除数据的应用名, 默认不清理
    :return:
    """

    # 清除应用数据
    # if clear_package_name:
    #     XiaoMaUtils.clear_data(clear_package_name)

    desired_caps = {}

    # 设备信息
    desired_caps['platformName'] = 'Android'
    # desired_caps['deviceName'] = '5203af01ea37b499'

    # 桌面的app信息
    desired_caps['appPackage'] = 'com.xiaoma.launcher'
    desired_caps['appActivity'] = '.main.ui.MainActivity'

    # 中文输入允许
    desired_caps['unicodeKeyboard'] = True
    desired_caps['resetKeyboard'] = True

    # 不清除应用数据
    desired_caps['noReset'] = False

    # 引入uiautomator2, 获取toast
    desired_caps['automationName'] = 'uiautomator2'

    # 修改超时时长, 默认是60秒
    desired_caps['newCommandTimeout'] = 3600

    # 声明我们的driver对象
    driver = webdriver.Remote('http://127.0.0.1:4723/wd/hub', desired_caps)

    return driver
